function cycle(){
	this.init = function (par,main,length,speed,interval){
		//par  主容器
		//main 滚动容器
		//length 一屏的个数
		//spped 滚动一次时间间隔
		//interval 滚动休息间隔
		this.par=par
		this.main=main
		this.length=length
		this.mains=$(this.main,this.par)
		this.alllength=this.mains.length
		if(speed==undefined){
			this.speed=1000
		}else{
			this.speed=speed
		}
		if(interval==undefined){
			this.interval=0
		}else{
			this.interval=interval
		}
		if(this.alllength>this.length){
			this.pars=$(this.par)
			this.firstmain=this.mains.slice(0,this.length).filter(main)
			this.lastmain=this.mains.eq(this.alllength-this.length-1).nextAll(main)
			this.height=this.mains.outerHeight()
			if(this.mains.css("margin-top")!='auto'){
				this.height=this.height+parseInt(this.mains.css("margin-top"))
			}
			if(this.mains.css("margin-bottom")!='auto'){
				this.height=this.height+parseInt(this.mains.css("margin-bottom"))
			}
			this.width=this.mains.outerWidth()
			if(this.mains.css("margin-left")!='auto'){
				this.width=this.width+parseInt(this.mains.css("margin-left"))
			}
			if(this.mains.css("margin-right")!='auto'){
				this.width=this.width+parseInt(this.mains.css("margin-right"))
			}
			if(this.par.substr(0,1)=='#'){
				this.elementtype='id'
			}else{
				this.elementtype='class'
			}
			this.pars.css({'position':'relative','overflow':'hidden'/*,'height':'100%','width':this.width*this.length*/}).wrapInner("<div "+this.elementtype+"='"+par.substr(1,par.length)+"main'></div>");
			this.cyclemain=$(par+"main")
			
			this.mains.first().before(this.lastmain.clone())
			this.mains.last().after(this.firstmain.clone())
			this.cyclemain.css({'position':'absolute','left':-this.width*this.length,'top':0,'height':this.height,'width':this.width*(this.alllength+this.length*2)})
		}
		this.ismove=false
		this.stoptag=false
	}
	this.cyclerun = function(dir,mode,speed,interval,auto,final){
		var _this=this
		if(this.alllength<=this.length){
			return false
		}
		//dir  方向
		//mode 0 滚一个，1 滚一屏
		//spped 滚动一次时间间隔
		//interval 滚动休息间隔
		//auto 是否不停滚动
		//final 最后位置
		if(this.ismove==false || (final!=undefined || (auto==1 && interval==0))){
			if(this.run){
				clearTimeout(this.run)
			}
			this.ismove=true
			if(dir==undefined){
				this.dir='left'
			}else{
				this.dir=dir
			}
			if(mode==undefined){
				this.mode=0
			}else{
				this.mode=mode
			}
			if(auto==undefined){
				this.auto=0
			}else{
				this.auto=auto
			}
			if(speed!=undefined){
				this.speed=speed
			}
			if(interval!=undefined){
				this.interval=interval
			}
			
			var cyclel=parseInt(this.cyclemain.position().left)
			var nextid=parseInt(cyclel/this.width)
			if(this.dir=='left'){
				if(final==undefined){
					if(mode==0){
						var space=1
					}else if(mode==1){
						var space=this.length
					}
					final=(nextid-space)*this.width
				}
				if (cyclel>-(this.width*(this.alllength+this.length))){
					this.cyclemain.css('left',cyclel-1)
				}else{
					this.cyclemain.css('left',-this.width*this.length)
					final=final+this.width*this.alllength
				}
				if(this.cyclemain.position().left>final){
					this.run = setTimeout(function(){
						_this.cyclerun(_this.dir,_this.mode,_this.speed,_this.interval,_this.auto,final)
					},(_this.speed/_this.width))
				}else{
					this.ismove=false
					if(this.auto==1){
						this.run = setTimeout(function(){
							final=undefined
							_this.cyclerun(_this.dir,_this.mode,_this.speed,_this.interval,_this.auto,final)
						},(_this.speed/_this.width)+_this.interval)
					}
				}
			}else if(this.dir=='right'){
				if(final==undefined){
					if(mode==0){
						var space=1
					}else if(mode==1){
						var space=this.length
					}
					final=(nextid+space)*this.width
				}
				if (cyclel<-this.width*this.length){
					this.cyclemain.css('left',cyclel+1)
				}else{
					this.cyclemain.css('left',-this.width*(this.alllength+this.length))
					final=final-this.width*this.alllength
				}
				if(this.cyclemain.position().left<final){
					this.run = setTimeout(function(){
						_this.cyclerun(_this.dir,_this.mode,_this.speed,_this.interval,_this.auto,final)
					},(_this.speed/_this.width))
				}else{
					this.ismove=false
					if(this.auto==1){
						this.run = setTimeout(function(){
							final=undefined
							_this.cyclerun(_this.dir,_this.mode,_this.speed,_this.interval,_this.auto,final)
						},(_this.speed/_this.width)+_this.interval)
					}
				}
			}
		}else{
			if(this.newrun){
				clearTimeout(this.newrun)
			}
			this.newrun=setTimeout(function(){
				_this.cyclerun(dir,mode,speed,interval,auto)
			},10)
		}
	}
	this.stoprun = function(mode){
		if(mode==0 || mode==undefined){
			this.auto=0
		}else{
			if(this.run){
				clearTimeout(this.run)
			}
		}
		if(this.newrun){
			clearTimeout(this.newrun)
		}
		this.ismove=false
	}
	//_this.stoprun(1)
}